package file.untils;

/**
 * @Author: zou
 * @email: 704572528@qq.com
 * @Date: 2020/10/31 12:10
 */
public class StringUntils {

    /**
     * 获取后面的名称
     * @param path
     * @return
     */
    public static String getLastName (String path) {
        if (!path.isEmpty()) {
            int iIndex = path.lastIndexOf("\\");
            if (iIndex != -1) {
                path = path.substring(iIndex+1, path.length());
            }
        }
        return path;
    }

    /**
     * 获取一开始到结尾
     * @param path
     * @return
     */
    public static String getStartToName (String path) {
        if (!path.isEmpty()) {
            int iIndex = path.lastIndexOf("\\");
            if (iIndex != -1) {
                path = path.substring(0, iIndex);
            }
        }
        return path;
    }

    /**
     * 交换二个人的尾部名字
     * @param orgain 旧
     * @param newName 新
     * @return
     */
    public static String exchangeName (String orgain,String newName) {

        if (!newName.isEmpty()) {
            newName = newName.trim();
            newName = getStartToName(orgain) + "\\"+ newName;
        }
        return newName;
    }
}
